/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DBObjects;

import java.util.ArrayList;

/**
 *
 * @author Aristarco
 */
public class dbForeignKey implements dbConnection {
    private dbTable sourceTable;
    private dbTable referredTable;

    private ArrayList<dbColumn[]> colRef = new ArrayList<dbColumn[]>();

    public dbForeignKey(dbTable source, dbTable referred )
    {
        this.sourceTable = source;
        this.referredTable = referred;
    }
    public boolean addColumnCoupleToFk(dbColumn sourceColumn, dbColumn targetColumn)
    {
        if (!sourceTable.hasColumn(sourceColumn) ||
                 !referredTable.hasColumn(targetColumn))
            return false;
        getColRef().add(new dbColumn[]{sourceColumn,targetColumn});
        return true;
    }

    /**
     * @return the sourceTable
     */
    public dbTable getSourceTable() {
        return sourceTable;
    }

    /**
     * @param sourceTable the sourceTable to set
     */
    public void setSourceTable(dbTable sourceTable) {
        this.sourceTable = sourceTable;
    }

    /**
     * @return the referredTable
     */
    public dbTable getReferredTable() {
        return referredTable;
    }

    /** FORSE QUI CONVIENE TOGLIERE IL METODO O ASSOCIARE LE
     *  COLONNE DI DESTINAZIONE ALLA TABELLA DI DESTINAZIONE
     * @param referredTable the referredTable to set
     */
    public void setReferredTable(dbTable referredTable) {
        this.referredTable = referredTable;
    }

    /**
     * @return the colRef
     */
    public ArrayList<dbColumn[]> getColRef() {
        return colRef;
    }

    /**
     * @param colRef the colRef to set
     */
    public void setColRef(ArrayList<dbColumn[]> colRef) {
        this.colRef = colRef;
    }

    @Override
    public dbObject getSource() {
        return this.sourceTable;
    }

    @Override
    public dbObject getDestination() {
        return this.referredTable;
    }

    @Override
    public int getType() {
        return dbConnection.FK;
    }



}
